package com.bage.finance.admin.api.controller;


import com.bage.common.dto.ApiResponse;
import com.bage.common.dto.TokenResponse;

import com.bage.finance.biz.dto.form.*;
import com.bage.finance.biz.service.MemberLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.GetSplitState;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.signature.qual.MethodDescriptor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="用户登录模块")
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping(value = "/login")
public class LoginController {

    final MemberLoginService memberLoginService;
    @ApiOperation(value = "获取客户端id")
    @GetMapping(value = "/getClientId")
    public ApiResponse<String> getClientId() {
        String result = memberLoginService.getClientId();
        return ApiResponse.success(result);
    }

    /**
     *
     * @param form
     * @return
     */
    @ApiOperation(value = "获取图形验证码")
    @GetMapping(value = "/getBase64Code")
    public ApiResponse<String> getBase64Code(@Validated @ModelAttribute GetBase64CodeForm form){

        String base64Code = memberLoginService.getBase64Code(form);
        return  ApiResponse.success(base64Code);
    }
    @ApiOperation(value = "获取短信验证码")
    @GetMapping(value = "/sendSmsCode")
public ApiResponse<Void> sendSmsCode(@Validated @ModelAttribute GetSmsCodeForm form){
        memberLoginService.sendSmsCode(form);
        return  ApiResponse.success();
    }


    @ApiOperation(value = "查询接口")
    @GetMapping(value = "/sendSmsCode1")
    public ApiResponse<List<String>> sendSmsCode1(){
        List<String> smsCodeTypeList = memberLoginService.getSmsCodeTypeList();

        return  ApiResponse.success(smsCodeTypeList);
    }

    @ApiOperation(value = "手机密码登录")
    @PostMapping(value = "/phonePasswordLogin")
    public ApiResponse<TokenResponse> phonePasswordLogin(@Validated @RequestBody PhonePasswordLoginForm form) {
        TokenResponse tokenResponse = memberLoginService.phonePasswordLogin(form);
        return ApiResponse.success(tokenResponse);
    }
    @ApiOperation(value = "手机短信登录")
    @PostMapping(value = "/phoneSmsCodeLogin")
    public ApiResponse<TokenResponse> phoneSmsCodeLogin(@Validated @RequestBody PhoneSmsCodeLoginForm request) {
        TokenResponse tokenResponse = memberLoginService.phoneSmsCodeLogin(request);
        return ApiResponse.success(tokenResponse);
    }
}
